/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				NoPeasCompositeFP
 
Function						: 				A class for detecting the pattern 
												of having no peasant because of 
												a peasant getting killed and at the same 
												time the attacking units are idle
****************************************************************************/
package behavioradaptation.failurepattern;


import java.util.List;
import java.util.Vector;

import trace.Entry;
import trace.Trace;
import behavioradaptation.analysisdata.AbstractedTrace;
import behavioradaptation.analysisdata.FPSuccessData;
import behavioradaptation.analysisdata.FailureTypes;
import behavioradaptation.analysisdata.FixData;
import behavioradaptation.analysisdata.IdleData;
import behavioradaptation.analysisdata.PlanFailuresData;

public class NoPeasCompositeFP {

	public boolean detectPattern(List<PlanFailuresData> a_planFailuresList, AbstractedTrace a_abstractedtrace, FixData a_fxdata) 
	{
		PeasKilledAvAttUnitsFP pkaau = new PeasKilledAvAttUnitsFP();
		Vector <FPSuccessData> sdata = pkaau.detectPattern(a_abstractedtrace);
		boolean patternfound = false;
		Trace a_trace = a_abstractedtrace.getTrace();
		for(int i = 0; i < a_planFailuresList.size(); i++)
		{
			PlanFailuresData pf = (PlanFailuresData)a_planFailuresList.get(i);
			List failurelist = pf.getFailures();
			for(int j = 0; j < failurelist.size(); j++)
			{	
				FailureTypes.m_failuretype  ftype  = (FailureTypes.m_failuretype) failurelist.get(j);
				if(ftype == FailureTypes.m_failuretype.NO_PEASANT) 
				{
					if(sdata.size() != 0 )
					{	
						FPSuccessData d = (FPSuccessData) sdata.get(0);
						Vector<IdleData> idata = d.getIdleData();
						int index = pf.getIndex();
						int nopeasantcycle = (int)((Entry)a_trace.getTrace().get(index)).getTime();
						for(int k = 0; k < idata.size(); k++)			
						{
							IdleData idat = (IdleData)idata.get(k);
							if(idat.getStartCycle() < nopeasantcycle)
							{
								patternfound = true;
								a_fxdata = new FixData();
								a_fxdata.m_pfd = pf;
								a_fxdata.m_scd = sdata;
								return patternfound;
							}	
						}														
					}
				}
			}
		}
		return patternfound;
	}	
}
